package cn.tedu.crm.refund.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.tedu.crm.base.pojo.PageObject;
import cn.tedu.crm.base.response.JsonResult;
import cn.tedu.crm.refund.pojo.dto.*;
import cn.tedu.crm.refund.pojo.vo.ContractVO;
import cn.tedu.crm.refund.pojo.vo.CustomerVO;
import cn.tedu.crm.refund.pojo.vo.DepositVO;
import cn.tedu.crm.refund.pojo.vo.RefundVO;
import cn.tedu.crm.refund.service.RefundService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/crm/refund")
public class RefundController {
    @Autowired
    private RefundService refundService;

    @SaCheckPermission("crm:finance:chargeback:select")
    @GetMapping("selectById/{id}")
    public JsonResult selectById(@PathVariable Long id){
        RefundVO refundVO = refundService.selectById(id);
        return JsonResult.ok(refundVO);
    }

    @GetMapping("selectContract/{id}")
    public JsonResult selectContract(@PathVariable Long id){
        ContractVO contractVO = refundService.selectContract(id);
        return JsonResult.ok(contractVO);
    }

    @GetMapping("selectDeposit/{id}")
    public JsonResult selectDeposit(@PathVariable Long id){
        DepositVO depositVO = refundService.selectDeposit(id);
        return JsonResult.ok(depositVO);
    }

    @GetMapping("selectCustomer/{id}")
    public JsonResult selectCustomer(@PathVariable Long id){
        CustomerVO customerVO = refundService.selectCustomer(id);
        return JsonResult.ok(customerVO);
    }

    @SaCheckPermission("crm:finance:chargeback:handle")
    @PostMapping("saveStatus")
    public JsonResult saveStatus(SaveStatusParam saveStatusParam){
        log.debug("saveStatusParam:"+saveStatusParam);
        refundService.saveStatus(saveStatusParam);
        return JsonResult.ok();
    }

    @PostMapping("saveAudit1")
    public JsonResult saveAudit1(SaveAudit1Param saveAudit1Param){
        refundService.saveAudit1(saveAudit1Param);
        return JsonResult.ok();
    }

    @PostMapping("saveAudit2")
    public JsonResult saveAudit2(SaveAudit2Param saveAudit2Param){
        refundService.saveAudit2(saveAudit2Param);
        return JsonResult.ok();
    }

    @SaCheckPermission("crm:finance:chargeback")
    @GetMapping("/select")
    public JsonResult selectRefundList(RefundQuery query) {
        PageObject<RefundVO> pageObject = PageObject.page(
                query.getPageNum(), query.getPageSize(), () -> refundService.selectRefundList(query));
        return JsonResult.ok(pageObject);
    }


}
